bb6fec762386c56677b2245e447ee33c77597f27,VUE2/src/tufts/vue/DataSourceList.java,DataSourceList,drop,#DropTargetDropEvent#,84
Before Change
int dropLocation = locationToIndex(e.getLocation());
this.setSelectedIndex(dropLocation);
DataSource ds = (DataSource)getSelectedValue();
System.out.println("Selected datasource:"+ds.getDisplayName());
try {
FavoritesWindow fw = (FavoritesWindow)ds.getResourceViewer();
VueDandDTree favoritesTree = fw.getFavoritesTree();
After Change
Object over = locationToValue(e.getLocation());
if (DEBUG.DND) out("DROP over " + over);
if (over instanceof FavoritesDataSource) {
if (DEBUG.DND) out("drag ACCEPTED");
e.acceptDrop(e.getDropAction());
} else {
if (DEBUG.DND) out("drag rejected");
e.rejectDrop();
return;
}
int current = this.getSelectedIndex();
setSelectedIndex(locationToIndex(e.getLocation()));
DataSource ds = (DataSource)getSelectedValue();
if (DEBUG.DND) System.out.println("DROP ON DATA SOURCE: " + ds.getDisplayName());
try {
FavoritesWindow fw = (FavoritesWindow)ds.getResourceViewer();
VueDandDTree favoritesTree = fw.getFavoritesTree();
favoritesTree.setRootVisible(true);
DefaultTreeModel model = (DefaultTreeModel)favoritesTree.getModel();
FavoritesNode rootNode = (FavoritesNode)model.getRoot();
boolean success = true;
Transferable transfer = e.getTransferable();
DataFlavor[] dataFlavors = transfer.getTransferDataFlavors();
String resourceName = null;
java.util.List fileList = null;
java.util.List resourceList = null;
if (DEBUG.DND) System.out.println("RESOURCE TRANSFER FOUND: " + transfer);
try {
if (transfer.isDataFlavorSupported(Resource.DataFlavor)) {
resourceList = (java.util.List) transfer.getTransferData(Resource.DataFlavor);
java.util.Iterator iter = resourceList.iterator();
while(iter.hasNext()) {
Resource resource = (Resource) iter.next();
if (DEBUG.DND) System.out.println("RESOURCE FOUND: " + resource);
ResourceNode newNode =new ResourceNode(resource);
model.insertNodeInto(newNode, rootNode, 0);
favoritesTree.expandPath(new TreePath(rootNode.getPath()));
favoritesTree.setRootVisible(false);
}
} else if (transfer.isDataFlavorSupported(DataFlavor.javaFileListFlavor)){
fileList = (java.util.List)transfer.getTransferData(DataFlavor.javaFileListFlavor);
java.util.Iterator iter = fileList.iterator();
while(iter.hasNext()){
File file = (File)iter.next();
if (file.isDirectory()){
try{
LocalFilingManager manager = new LocalFilingManager(); // get a filing manager
osid.shared.Agent agent = null;
LocalCabinet cab = new LocalCabinet(file.getAbsolutePath(),agent,null);
CabinetResource res = new CabinetResource(cab);
CabinetEntry entry = res.getEntry();
if (file.getPath().toLowerCase().endsWith(".url")) {
String url = convertWindowsURLShortCutToURL(file);
if (url != null) {
res.setSpec("file://" + url);
String resName;
if (file.getName().length() > 4)
resName = file.getName().substring(0, file.getName().length() - 4);
else
resName = file.getName();
res.setTitle(resName);
}
}
CabinetNode cabNode = null;
if (entry instanceof RemoteCabinetEntry)
cabNode = new CabinetNode(res, CabinetNode.REMOTE);
else
cabNode = new CabinetNode(res, CabinetNode.LOCAL);
model.insertNodeInto(cabNode, rootNode, 0);
favoritesTree.expandPath(new TreePath(rootNode.getPath()));
favoritesTree.setRootVisible(false);
}catch (Exception ex) {System.out.println("DataSourceList.drop: "+ex);}
} else{
try{
LocalFilingManager manager = new LocalFilingManager(); // get a filing manager
osid.shared.Agent agent = null;
LocalCabinet cab = new LocalCabinet(file.getAbsolutePath(),agent,null);
CabinetResource res = new CabinetResource(cab);
res.setTitle(file.getAbsolutePath());
CabinetEntry oldentry = res.getEntry();
res.setEntry(null);
if (file.getPath().toLowerCase().endsWith(".url")) {
// Search a windows .url file (an internet shortcut)
// for the actual web reference.
String url = convertWindowsURLShortCutToURL(file);
if (url != null) {
//resourceSpec = url;
res.setSpec("file://" + url);
String resName;
if (file.getName().length() > 4)
resName = file.getName().substring(0, file.getName().length() - 4);
else
resName = file.getName();
res.setTitle(resourceName);
}
}
CabinetNode cabNode = null;
if (oldentry instanceof RemoteCabinetEntry)
cabNode = new CabinetNode(res, CabinetNode.REMOTE);
else
cabNode = new CabinetNode(res, CabinetNode.LOCAL);
model.insertNodeInto(cabNode, rootNode, 0);
favoritesTree.expandPath(new TreePath(rootNode.getPath()));
favoritesTree.setRootVisible(false);
}catch (Exception ex) {System.out.println("DataSourceList.drop: "+ex);}
}
}
}
else if (transfer.isDataFlavorSupported(DataFlavor.stringFlavor)){
String dataString = (String)transfer.getTransferData(DataFlavor.stringFlavor);
Resource resource = new MapResource(dataString);
ResourceNode newNode =new ResourceNode(resource);
model.insertNodeInto(newNode, rootNode, 0);
favoritesTree.expandPath(new TreePath(rootNode.getPath()));
favoritesTree.setRootVisible(false);
}
} catch (Exception ex) {
ex.printStackTrace();
}
e.dropComplete(success);
favoritesTree.setRootVisible(true);
favoritesTree.expandRow(0);
favoritesTree.setRootVisible(false);
this.setSelectedIndex(current);
} catch (Exception ex) {
if (DEBUG.DND) tufts.Util.printStackTrace(ex);
this.setSelectedIndex(current);
VueUtil.alert(null, "You can only add resources to a Favorites Datasource","Resource Not Added");
}